package com.itheima.system.service.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.system.dao.RoleMapper;
import com.itheima.system.pojo.Role;
import com.itheima.system.service.RoleService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 添加角色
     * @param role
     */
    @Override
    public void add(Role role) {
        role.setStatus("0");
        roleMapper.insertSelective(role);
    }

    /**
     * 删除角色
     * @param id
     */
    @Override
    public void delete(Long id) {
        roleMapper.updateStatusById(id);
    }


    /**
     * 修改角色信息
     * @param
     */
    @Override
    public void update(Role role) {
      roleMapper.updateById(role.getId(),role.getRolename());
    }

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<Role> findAll() {
        return roleMapper.selectAll();
    }

    /**
     * 分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Role> findPage(int page, int size) {
        PageHelper.startPage(page,size);
        return (Page<Role>)roleMapper.selectAll();
    }

}
